<?php

use console\db\channels\TransferTableMigration;
use yii\db\Query;

/**
 * 会员卡办卡快递信息转移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m310030_000009_t_vipcard_card_express extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * 是否先清理本地数据表
     */
    public $beforeTruncateTargetTable = false;

    /**
     * @inheritdoc
     */
    public function buildQuery() {
        return (new Query())->from('{{%' . $this->sourceTable . '}}')->where(['>', 'orderid', 73791]);
    }

    /**
     * @inheritdoc
     */
    public function validateTransfer(&$data) {
        if (!parent::validateTransfer($data)) {
            return false;
        }
        if (!$data['shipping_name']) {
            return false;
        }
        return true;
    }

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'freight_receiver' => 'trade_vipcard',
            ],
            'columns' => [
                'user_id' => 'uid',
                'name' => 'shipping_name',
                'mobile' => 'shipping_phone',
                'province' => 'shipping_province',
                'city' => 'shipping_city',
                'district' => 'shipping_district',
                'address' => 'shipping_address',
                'mark' => 'orderid',
                'from' => function() {
                    return 'card2';
                },
                'price' => 'shipping_fee',
                'status' => function() {
                    return 10;
                },
                'created_at' => 'inputtime',
                'updated_at' => 'updatetime',
            ]
        ];
    }

}
